<?php
class Util{
	public function GetImageAndTxt($txt){
		$arr = array();
		$detail = array();
		preg_match('/\<img.*?\/\>/',$txt,$arr);
		if(count($arr)){
			$imgtxt = $arr[0];
			preg_match('/src="(.*?)" /',$imgtxt,$arr);
			if(count($arr) < 2){
				preg_match('/src=\'(.*?)\' /',$imgtxt,$arr);
			}
		}		
		$txt = preg_replace('/\<.*?\>/','',$txt);
		$detail['img'] = "../images/img-solution-3.jpg";
		if(count($arr) == 2) $detail['img'] = $arr[1];
		$detail['txt'] = $txt;
		return $detail;
	}
	public function SavePic($name){
		if(!isset($_FILES[$name])) return "";
		$upFile = $_FILES[$name];
		if($upFile['error']>0)
		{
			return  "";
		}  
		if(!eregi("image",$upFile['type']))
		{
			return "";
		} 
		$file = $upFile['tmp_name'];
		$ext = substr($upFile['name'],strrpos($upFile['name'],'.'));
		$newfile = "../userfiles/".rand(111111,999999).rand(111111,999999).time().$ext;
		if(is_uploaded_file($upFile['tmp_name']))
		{			
			$re= move_uploaded_file ($file,$newfile);
			if(!$re) return "";
		}
		return $newfile;
	}
}
?>